//
//  HomeVCTopCell.swift
//  weibo1
//
//  Created by 李进 on 15/10/21.
//  Copyright © 2015年 李进. All rights reserved.
//

import UIKit

class HomeVCTopCell: UIView {
    
    
    /// 微博视图模型
    var viewModle: userFriendViewModel? {
        didSet {
            // 姓名
            nameLabel.text = viewModle?.status.user?.screen_name
            
            // 头像
            iconImageView.sd_setImageWithURL(viewModle?.userProfileUrl,
                placeholderImage: viewModle?.userDefaultIconView)
            // 会员图标
            memberIconView.image = viewModle?.userMemberImage
            // 认证图标
            vipIconView.image = viewModle?.userVipImage
            
            // TODO - 后续会讲
            // 时间
            timeLabel.text = "刚刚" // viewModle?.status.created_at
            sourceLabel.text = "来自 黑马微博" // viewModle?.status.source
        }
    }

    override init(frame:CGRect){
        super.init(frame: frame)
        
        setupUI()
        
    }
        
    

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /// 懒加载topcell上面的控件
    ///1.>头像视图
    private lazy var iconImageView:UIImageView = UIImageView(imageName: "avatar_default_big")
    
    ///2.>姓名
    private lazy var nameLabel: UILabel = UILabel(titlt: "打死你", fontsize: 14)
    
    ///3.>会员图标
    private lazy var memberIconView: UIImageView = UIImageView(imageName: "common_icon_membership_level1")
    ///4.>vip图标
    private lazy var vipIconView: UIImageView = UIImageView(imageName: "avatar_vip")
    
    ///5.> 时间标签
    private lazy var timeLabel: UILabel = UILabel(titlt: "现在", fontsize: 11, fontcolor: UIColor.orangeColor())
    
    /// 来源标签<#T##UIColor#>
    private lazy var sourceLabel: UILabel = UILabel(titlt: "来源", fontsize: 11 )
    
    

}


// MARK: - 设置ui
extension HomeVCTopCell{
    
    func setupUI(){
        
        // 0. 添加分隔视图
        let sepView = UIView()
        sepView.backgroundColor = UIColor.lightGrayColor()
        addSubview(sepView)
        
        addSubview(iconImageView)
        addSubview(nameLabel)
        addSubview(memberIconView)
        addSubview(vipIconView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        
        
        sepView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            
            make.right.equalTo(self.snp_right)
            
            make.height.equalTo(HomeCellMargin)
        }
        //设置自动布局
        iconImageView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(HomeCellMargin)
            make.top.equalTo(sepView.snp_bottom).offset(HomeCellMargin)
            make.width.equalTo(HomeCellIconWidth)
            make.height.equalTo(HomeCellIconWidth)
        }
        
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconImageView.snp_top)
            make.left.equalTo(iconImageView.snp_right).offset(HomeCellMargin)
        }
        memberIconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(nameLabel.snp_top)
            make.left.equalTo(nameLabel.snp_right).offset(HomeCellMargin)
        }
        vipIconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconImageView.snp_right)
            make.centerY.equalTo(iconImageView.snp_bottom)
        }
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(iconImageView.snp_bottom)
            make.left.equalTo(iconImageView.snp_right).offset(HomeCellMargin)
        }
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(timeLabel.snp_bottom)
            make.left.equalTo(timeLabel.snp_right).offset(HomeCellMargin)
        }
       
        
    }
}